package com.ruoyi.blog.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BlogLinks;
import com.ruoyi.blog.service.IBlogLinksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客友情链接Controller
 * 
 * @author 谭潇
 * @date 2021-05-05
 */
@RestController
@RequestMapping("/blog/links")
public class BlogLinksController extends BaseController
{
    @Autowired
    private IBlogLinksService blogLinksService;

    /**
     * 查询博客友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('blog:links:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogLinks blogLinks)
    {
        startPage();
        List<BlogLinks> list = blogLinksService.selectBlogLinksList(blogLinks);
        return getDataTable(list);
    }

    /**
     * 导出博客友情链接列表
     */
    @PreAuthorize("@ss.hasPermi('blog:links:export')")
    @Log(title = "博客友情链接", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BlogLinks blogLinks)
    {
        List<BlogLinks> list = blogLinksService.selectBlogLinksList(blogLinks);
        ExcelUtil<BlogLinks> util = new ExcelUtil<BlogLinks>(BlogLinks.class);
        return util.exportExcel(list, "博客友情链接数据");
    }

    /**
     * 获取博客友情链接详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:links:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(blogLinksService.selectBlogLinksById(id));
    }

    /**
     * 新增博客友情链接
     */
    @PreAuthorize("@ss.hasPermi('blog:links:add')")
    @Log(title = "博客友情链接", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogLinks blogLinks)
    {
        return toAjax(blogLinksService.insertBlogLinks(blogLinks));
    }

    /**
     * 修改博客友情链接
     */
    @PreAuthorize("@ss.hasPermi('blog:links:edit')")
    @Log(title = "博客友情链接", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogLinks blogLinks)
    {
        return toAjax(blogLinksService.updateBlogLinks(blogLinks));
    }

    /**
     * 删除博客友情链接
     */
    @PreAuthorize("@ss.hasPermi('blog:links:remove')")
    @Log(title = "博客友情链接", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(blogLinksService.deleteBlogLinksByIds(ids));
    }
}
